home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 21
/
CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso
/
CUCD
/
Magazine
/
C_Tutorial
/
Part-9
/
wb2
/
bitmap.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-10-27
|
2KB
|
69 lines
#include "bitmap.h"
#include "screen.h"
#include<exec/memory.h>
#include<stdio.h>
#include<clib/exec_protos.h>
#include<clib/graphics_protos.h>
/* Global handle for our bitmap */
static struct BitMap* bitmap = NULL;
/* Global record of requested depth, width and height */
static int depth, width, height;
/* Create a bitmap */
int createBitmap()
{
struct Screen* scr = getScreen();
/* The MEMF_CLEAR flag is vital, since it zeroes the allocated memory. */
/* Thus the pointers in the bitmap will be NULL, if we don't manage to */
/* allocate them properly. */
if(bitmap = AllocMem(sizeof(struct BitMap), MEMF_PUBLIC | MEMF_CLEAR))
{
int plane;
/* Our new BitMap has sizes based on the screen BitMap */
depth = scr->BitMap.Depth;
width = scr->Width;
height = scr->Height;
InitBitMap(bitmap, depth, width, height);
for(plane = 0; plane < depth; plane++)
{
bitmap->Planes[plane] = AllocRaster(width, height);
if(bitmap->Planes[plane] == NULL)
{
printf("Error: could not create planes for bitmap\n");
return FALSE;
}
}
/* If we get here, we succeeded. */
return TRUE;
}
else
printf("Error: could not create bitmap\n");
return FALSE;
}
/* Free any allocated bitmap */
void freeBitmap()
{
if(bitmap)
{
int plane;
for(plane = 0; plane < depth; plane++)
{
if(bitmap->Planes[plane])
FreeRaster(bitmap->Planes[plane], width, height);
}
FreeMem(bitmap, sizeof(struct BitMap));
/* Set to NULL to indicate that it's been freed */
bitmap = NULL;
}
}
struct BitMap* getBitmap()
{
return bitmap;
}